#include<bits/stdc++.h>
using namespace std;
using ll = long long ;
ll r(ll n){
    ll m=0;
    while(n>0){
        m=m*10+n%10;
        n/=10;
    }
    return m;
}
bool prime(ll n){
    if(n==2)return true;
    if(n<2||n%2==0)return false;
    for(ll c=3;c*c<=n;c+=2){
        if(n%c==0)return false;
    }
    return true;
}
bool ok(ll n){
    return r(n)==n&&prime(n);
}
int main(){
    ll a,b;
    while(cin>>a>>b){
        for(ll i=a;i<=b;i++){
            if(ok(i)){
                cout<<i<<endl;
            }
        }
        cout<<endl;
    }

    return 0;
}